﻿
using System;
using System.Threading;
using System.Windows.Forms;

namespace Scheduledscheduling
{
    static class Program
    {

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {

            if (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length > 1)
            {
                MessageBox.Show("已有另一個程序在运行！", "提示信息");
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
                AppDomain currentDomain = AppDomain.CurrentDomain;

                currentDomain.UnhandledException += new UnhandledExceptionEventHandler(TopLevelExceptionHandler);

                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            }
        }



        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            MessageBox.Show("非常抱歉，系统出现异常，请重新启动系统。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

            Application.Exit();
        }

        private static void TopLevelExceptionHandler(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show("非常抱歉，系统出现异常，请重新启动系统。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

            Application.Exit();
        }
    }
}
